/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package adaptationLayer;

import contextManagement.ContextBroker;
import java.beans.PropertyChangeEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import userInterface.GraphicalUserInterface;

/**
 *
 * @author huangqing
 */
public class TemperatureAdapter extends Adapter{
    public TemperatureAdapter(GraphicalUserInterface gui){
        myGUI = gui;
    }


   public void setContextBroker(ContextBroker cb) {
        myBroker = cb;
        myBroker.addPropertyChangeListener("temps", this);
    }

  
    public void propertyChange(PropertyChangeEvent pce) {
       
        if (pce.getPropertyName().equals("temps")){
            String temperature = (String) pce.getNewValue();
            float temps = Float.parseFloat(temperature);
            if (temps<0) {
                temps = 0 - temps;
                Float f = new Float(temps);
                temperature = f.toString();
            }
            System.out.println(pce.getNewValue());
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            String dateStr = sdf.format(new Date());
            Object[] ob = {dateStr, temperature};
            myGUI.addData(ob);

        }
    }
}
